package com.rcy.server.service;

import org.springframework.stereotype.Service;
import com.rcy.server.pojo.MyFile;
import com.rcy.server.Repository.FileRepository;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
import org.springframework.transaction.annotation.Transactional;

/**
*
* @author RuicyWu
*@Date 2021-11-06 09:24:43
*/
@Service
public class FileService{

	@Autowired
	private FileRepository rep;

/**
 * 根据id查询File
 * @param id
 * @return File
 */
   public MyFile findById(Integer id){return rep.findById(id).get();}

/**
 * 根据id删除File
 * @param id
 */
   @Transactional(rollbackFor = Exception.class)
   public void remove(Integer id){rep.deleteById(id);}

/**
 * 新增File
 * @param entity
 */
   @Transactional(rollbackFor = Exception.class)
   public void add(MyFile entity){rep.save(entity);}

/**
 * 修改File
 * @param entity
 */
   @Transactional(rollbackFor = Exception.class)
   public void edit(MyFile entity){rep.save(entity);}

/**
 * 查询所有File
 * @return List<File>
 */
   public List<MyFile> findAll(){return rep.findAll();}

    /**
     * 根据文件名查询文件元数据
     * @param fileName
     * @return 文件元数据对象
     */
   public MyFile getFileMetaDataByFileName(String fileName)
   {
       return rep.findByFileName(fileName);
   }
}
